const acorn = require('acorn')

function ast(str) {
  const astTree = acorn.parse(str, {
    locations: true, // 索引位置
    ranges: true,
    sourceType: "module",
    ecmaVersion: 7,
  })
  return astTree.body.filter(node => node.type == "VariableDeclaration").reduce((pre, cur) => {
    let key = cur.declarations[0].id.name
    pre[key] = true
    return pre
  }, {})
}
module.exports = ast
